home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: news.sprintlink.net!news1!news
- From: rclark@iquest.net (Robert B. Clark)
- Subject: Re: C beginner needs your help ASAP
- X-Nntp-Posting-Host: ind-004-236-169.iquest.net
- Message-ID: <3129feba.6644222@news.iquest.net>
- Sender: news@iquest.net (News Admin)
- Organization: IQuest Internet, Inc.
- X-Newsreader: Forte Agent .99d/16.182
- References: <4g862f$p0b@risky.ecs.umass.edu> <4g8ahd$p8b@spectator.cris.com>
- Date: Tue, 20 Feb 1996 17:03:00 GMT
-
- On 18 Feb 1996 22:51:25 GMT, aubrey@concentric.net (Aubrey Harrison)
- wrote:
-
- > char buf[3],filename[9];
- > int i;
- >
- > for(i=0; i<10; i++)
- > {
- > sprintf(buf,"%d",i);
- > strcpy( filename,"data");
- > strcat( filename, buf );
- > strcat( filename, ".ext");
- > printf( "%s\n", filename);
- > }
-
- Just a quick word--are you aware that non-format type characters in the
- format pattern string for sprintf() are simply copied verbatim to the
- target string? That is, for
-
- sprintf(buf,"This is numeral one (%d)",1)
-
- 'buf' will contain
-
- This is numeral one (1)
-
- So your code could have been simplified to
-
- sprintf(filename,"data%d.ext",i); /* Returns e.g. "data0.ext" */
-
- if 'filename' was of sufficient length.
- --
- Robert B. Clark <rclark@iquest.net>
- "Be wary of strong spirits. It can make you shoot at tax collectors...
- and miss." --RAH
-